﻿using System;
using CommonUtils.Models;

namespace DatabaseService.Model
{
    /// <summary>
    /// 分页数据模型
    /// </summary>
    public class PageTable : ModelBase
    {
        private int totalCounts;
        /// <summary>
        /// 总数
        /// </summary>
        public int TotalCounts 
        {
            get => totalCounts;
            set
            {
                Set(nameof(TotalCounts), ref totalCounts, value);
                if (isPage && pageSize > 0 && value > 0)
                {
                    PageCounts = (int)Math.Ceiling(totalCounts * 1.0 / pageSize);
                }
            }
        }

        private int pageSize = 20;
        /// <summary>
        /// 一页数据量
        /// </summary>
        public int PageSize
        {
            get => pageSize;
            set
            {
                Set(nameof(PageSize), ref pageSize, value);
                if (isPage && totalCounts > 0 && value > 0)
                {
                    PageCounts = (int)Math.Ceiling(totalCounts * 1.0 / pageSize);
                }
            }
        }

        private int pageCounts = 1;
        /// <summary>
        /// 页数
        /// </summary>
        public int PageCounts { get => pageCounts; set => Set(nameof(PageCounts), ref pageCounts, value); }

        private int pageIndex = 1;
        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get => pageIndex; set => Set(nameof(PageIndex), ref pageIndex, value); }

        private bool isPage = true;
        /// <summary>
        /// 是否分页
        /// </summary>
        public bool IsPage { get => isPage; set => Set(nameof(IsPage), ref isPage, value); }
    }
}
